package com.leven.easyerp.entity;

import java.util.Collections;
import java.util.List;

/**
 * 本系统使用的分页对象<br>
 * 注意：记录序列号是从0开始。页码是从1开始
 * 
 * @param <T>
 *            Page中记录的类型
 * @author Leven.Chen
 */
public class Page<T> {
	private int pageNo = 1;
	private int pageSize = 1;
	private boolean autoCount = true;
	private List<T> result = Collections.emptyList();
	private int totalCount = -1;

	public Page() {
	}

	public Page(int pageNo, int pageSize) {
		this.pageNo = pageNo;
		this.pageSize = pageSize;
	}

	public int getPageNo() {
		return pageNo;
	}

	public void setPageNo(int pageNo) {
		this.pageNo = pageNo;
	}

	public Page<T> pageNo(final int thePageNo) {
		setPageNo(thePageNo);
		return this;
	}

	public int getPageSize() {
		return pageSize;
	}

	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}

	public Page<T> pageSize(final int thePageSize) {
		setPageSize(thePageSize);
		return this;
	}

	public boolean isAutoCount() {
		return autoCount;
	}

	public void setAutoCount(boolean autoCount) {
		this.autoCount = autoCount;
	}

	public Page<T> autoCount(final boolean theAutoCount) {
		setAutoCount(theAutoCount);
		return this;
	}

	public List<T> getResult() {
		return result;
	}

	public void setResult(List<T> result) {
		this.result = result;
	}

	public int getTotalCount() {
		return totalCount;
	}

	public void setTotalCount(int totalCount) {
		this.totalCount = totalCount;
	}

	/**
	 * 根据pageNo和pageSize计算当前页第一条记录在总结果集中的位置，序号从0开始.
	 */
	public int getFirst() {
		return ((pageNo - 1) * pageSize);
	}
}
